package com.ruoyi.tcp.entity.time;

import com.ruoyi.tcp.entity.CustomerBaseEntity;
import com.ruoyi.tcp.util.TcpAesUtil;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.time.LocalDateTime;
import java.time.ZoneOffset;

/**
 * @author 蒋翔 SY100242
 * @date 2024/8/7 15:17
 * @email SY100242@hnlens.com
 */
@Setter
@Getter
@ToString
public class ServerTimeSyncMessageEntity extends CustomerBaseEntity {

    private static final long serialVersionUID = 1L;

    //设备编号
    private Long deviceNumber;
//    //响应消息长度
//    private Integer msgLen;
//    //时间
//    private LocalDateTime now;


    @Override
    public byte[] getOtherBytes() {
        ByteBuf buffer = Unpooled.buffer();
        byte[] deviceNumberBytes = TcpAesUtil.longToByteArray16(deviceNumber);
        buffer.writeBytes(deviceNumberBytes);
        byte[] nowBytes = TcpAesUtil.longToByteArray16(LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")));
        byte[] bytes = TcpAesUtil.intToByteArray(nowBytes.length);
        buffer.writeBytes(bytes);
        buffer.writeBytes(nowBytes);
        return ByteBufUtil.getBytes(buffer);
    }
}
